/// @tags: DPwithMonotoneQueue MonotoneDecision
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;
typedef long double LD;

int const N = 1e5 + 5, M = 35;
LL const LIM = 1e18;

int t, L, p, n, head, tail;
int len[N], last[N], l[N], r[N], q[N];
char str[N][M];
LL sum[N];
LD f[N];

inline LD qpow(LD x) {
  LD res = 1;
  int exp = p;
  for (; exp; exp >>= 1, x *= x)
    if (exp & 1) res *= x;
  return res;
}

inline LD calc(int j, int i) { return f[j] + qpow(abs(sum[i] - sum[j] - L - 1)); }

int output(int x) {
  int u = 1;
  if (last[x]) u = output(last[x]) + 1;
  for (int i = u; i < x; ++i) cout << str[i] << ' ';
  cout << str[x] << '\n';
  return x;
}

inline int main() {
  cin >> t;
  while (t--) {
    cin >> n >> L >> p;
    for (int i = 1; i <= n; i++) {
      cin >> str[i];
      len[i] = strlen(str[i]) + 1;
      sum[i] = sum[i - 1] + len[i];
    }
    head = tail = 1;
    q[1] = 0, l[0] = 1, r[0] = n;
    for (int i = 1; i <= n; i++) {
      while (r[q[head]] < i) ++head;
      int j = q[head];
      f[i] = calc(j, i);
      last[i] = j;
      if (calc(q[tail], n) < calc(i, n)) continue;
      while (calc(q[tail], l[q[tail]]) > calc(i, l[q[tail]])) --tail;
      j = q[tail];
      int ll = l[j], rr = n, mid;
      while (ll < rr) {
        mid = (ll + rr) >> 1;
        calc(i, mid) < calc(j, mid) ? rr = mid : ll = mid + 1;
      }
      r[q[tail]] = ll - 1;
      q[++tail] = i, l[i] = ll, r[i] = n;
    }
    if (f[n] > 1e18) cout << "Too hard to arrange\n";
    else {
      cout << (LL)f[n] << '\n';
      output(n);
    }
    cout << "--------------------\n";
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P1912 [NOI2009] 诗人小G.in", "r", stdin);
  freopen("P1912 [NOI2009] 诗人小G.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
